import { get, postJson } from '../utils/request';
import cloudbase from "@cloudbase/js-sdk";

// 登录
export function loginByAccount(params) {
    return new Promise((resolve, reject) => {
        // 使用全局的云开发实例
        const app = cloudbase.init({
            env: "cloud1-2gozbkkk09f11d05"
        });
        
        // 先进行匿名登录
        app.auth().signInAnonymously()
            .then(() => {
                // 匿名登录成功后调用云函数
                return app.callFunction({
                    name: 'Login',
                    data: {
                        action: 'login',
                        username: params.account,
                        password: params.password
                    }
                });
            })
            .then(res => {
                resolve({ data: res.result });
            })
            .catch(err => {
                reject(err);
            });
    });
}

//分页查询
export function page(params) {
    return get('/user/page',params)
}
